/*
 * @Author: your name
 * @Date: 2021-03-22 09:26:30
 * @LastEditTime: 2021-11-18 09:21:49
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \request\demo\server.js
 */
const express = require('express')
const webpack = require('webpack')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpackHotMiddleware = require('webpack-hot-middleware')
const {
	createProxyMiddleware
} = require('http-proxy-middleware')
const WebpackConfig = require('./webpack.config')

const app = express()
const compiler = webpack(WebpackConfig)

app.use(webpackDevMiddleware(compiler, {
	publicPath: WebpackConfig.output.publicPath,
	stats: {
		colors: true,
		chunks: false
	}
}))

app.use(webpackHotMiddleware(compiler))
app.use('/api', createProxyMiddleware({
	secure: false,
	changeOrigin: true,
	pathRewrite: {
		'^/api': '/api'
	}
}))
app.use(express.static(__dirname))

const port = process.env.PORT || 8085
module.exports = app.listen(port, () => {
	console.log(`Server listening on http://localhost:${port}, Ctrl+C to stop`)
})